package com.vvlive.caibao.smartcity.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ListView;

/**
 * Created by zhj on 2015/12/4.
 */
public class ViewStorage {

    /**
     * ListView的emptyView布局参数
     */
    private static final LayoutParams EMPTY_VIEW_LAYOUT_PARAMS
            = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    /**
     * 给ListView设置没有数据时要显示的视图
     * @param context
     * @param listView
     * @param id
     * @return
     */
    public static View setListEmptyView(Context context, ListView listView, int id){
        View view = LayoutInflater.from(context).inflate(id, null);
        view.setLayoutParams(EMPTY_VIEW_LAYOUT_PARAMS);
        ViewGroup group = (ViewGroup) listView.getParent();
        group.addView(view, group.getChildCount());
        listView.setEmptyView(view);
        return view;
    }
}
